home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / tools / cdfscope.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-04  |  8.6 KB  |  356 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                    Correct attribute scopes.
  4. *
  5. *  Version 2.0, 4-Mar-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  24-Apr-91, J Love    Original version (for CDF V2.1).
  10. *   V1.1  25-Jun-91, J Love    Added QOP.  Added PageInst.
  11. *   V1.2   1-Aug-91, J Love    TRUE/FALSE.  Use 'Exit'/'ExitBAD'.  Use
  12. *                'CDFlib'.  Added 'log' qualifier.
  13. *   V2.0   4-Mar-92, J Love    Modified for IBM PC port.
  14. *
  15. ******************************************************************************
  16. *
  17. *   This program corrects all of the assumed attribute scopes to the
  18. *  corresponding definite scopes (ie...
  19. *
  20. *    ASSUMED_GLOBAL_SCOPE ---> GLOBAL_SCOPE, and
  21. *    ASSUMED_VARIABLE_SCOPE ---> VARIABLE_SCOPE)
  22. *
  23. *  Assumed scopes are normally the result of a Version 1 CDF being converted
  24. *  to a Version 2 CDF.
  25. *
  26. ******************************************************************************/
  27.  
  28. #include "cdfdist.h"
  29. #include "cdfscope.h"
  30.  
  31. /******************************************************************************
  32. * Global variables.
  33. ******************************************************************************/
  34.  
  35. CDFid id;
  36. Boolean mLog;
  37.  
  38. /******************************************************************************
  39. * Main.
  40. ******************************************************************************/
  41.  
  42. #if defined(vms)
  43. main (argc, argv)
  44. #else
  45. void main (argc, argv)
  46. #endif
  47. int argc;
  48. char *argv[];
  49. {
  50. CDFstatus status;
  51. long scope;
  52. long Nattrs;
  53. long attrN;
  54. long VARcount = 0;
  55. long GBLcount = 0;
  56. char answer[2];
  57. long confirm;
  58. char CDFname[80];
  59. char attrName[CDF_ATTR_NAME_LEN];
  60.  
  61. QOP *qop;
  62. long count;
  63.  
  64. static char *validQuals[] = { "confirm", "noconfirm", "log", "nolog", NULL };
  65. static int optRequired[] = { FALSE, FALSE, FALSE, FALSE, 0 };
  66.  
  67. static char *instructions[] = {
  68. #if defined(vms)
  69. "Usage:         $ CDFSCOPE [/[no]CONFIRM] [/[no]LOG] <cdf-path>",
  70. #endif
  71. #if defined(unix)
  72. "Usage:         % cdfscope [-[no]confirm] [-[no]log] <cdf-name>",
  73. #endif
  74. #if defined(__MSDOS__)
  75. "Usage:         > cdfscope [-[no]confirm] [-[no]log] <cdf-name>",
  76. #endif
  77. "",
  78. "Purpose:       CDFscope is used to correct the assumed scopes that may be",
  79. "               found in a CDF.  These assumed scopes are normally a result",
  80. "               of converting a Version 1 CDF to a Version 2 CDF.",
  81. "",
  82. "Parameter(s):  <cdf-path>",
  83. "                  The pathname of the CDF to be corrected (do not specify an",
  84. "                  extension).",
  85. "",
  86. #if defined(vms)
  87. "Qualifier(s):  /[no]CONFIRM",
  88. #endif
  89. #if defined(unix) | defined(__MSDOS__)
  90. "Qualifier(s):  -[no]confirm",
  91. #endif
  92. "                  Specifies whether or not the program prompts for",
  93. "                  confirmation before correcting a scope.  The valid",
  94. "                  responses to the confirmation prompts are as follows.",
  95. "",
  96. "                    Y/y   Yes, correct the scope (assumed --> definite).",
  97. "                    N/n   No, don't correct the scope.",
  98. "                    G/g   Correct the scope to GLOBAL_SCOPE.",
  99. "                    V/v   Correct the scope to VARIABLE_SCOPE.",
  100. "",
  101. "                  The default is to confirm all scopes without prompting for",
  102. "                  confirmation.",
  103. "",
  104. #if defined(vms)
  105. "               /[no]LOG",
  106. #endif
  107. #if defined(unix) | defined(__MSDOS__)
  108. "               -[no]log",
  109. #endif
  110. "                  Specifies whether or not message logging is enabled.",
  111. "                  The default is message logging disabled.",
  112. "",
  113. #if defined(vms)
  114. "Example(s):    $ CDFSCOPE TOGA_ECMWF",
  115. "               $ CDFSCOPE/CONFIRM/NOLOG TOGA_ECMWF",
  116. #endif
  117. #if defined(unix)
  118. "Example(s):    % cdfscope toga_ecmwf",
  119. "               % cdfscope -confirm -nolog ../toga_ecmwf",
  120. #endif
  121. #if defined(__MSDOS__)
  122. "Example(s):    > cdfscope ..\\toga",
  123. "               > cdfscope -confirm -nolog a:\\cdfs\\toga",
  124. #endif
  125. NULL };
  126.  
  127. /******************************************************************************
  128. * Get qualifiers/options/parameters.
  129. ******************************************************************************/
  130.  
  131. switch (argc == 1) {
  132.   case 1:
  133.     PageInst (instructions);
  134.     Exit;
  135.   default:
  136.     qop = Qop (argc, argv, validQuals, optRequired);
  137.     if (qop == NULL) ExitBAD;
  138.  
  139.     if (qop->Nparms < 1) {
  140.       printf ("Missing parameter.\n");
  141.       ExitBAD;
  142.     }
  143.     else {
  144.       strcpy (CDFname, qop->parms[0]);
  145.     }
  146.  
  147.     count = 0;
  148.     if (qop->qualEntered[0]) count++;
  149.     if (qop->qualEntered[1]) count++;
  150.  
  151.     switch (count) {
  152.       case 0:
  153.     confirm = FALSE;
  154.     break;
  155.       case 1:
  156.     if (qop->qualEntered[0])
  157.       confirm = TRUE;
  158.     else
  159.       confirm = FALSE;
  160.     break;
  161.       default:
  162.     printf ("Conflicting qualifiers.\n");
  163.     ExitBAD;
  164.     break;
  165.     }
  166.  
  167.     count = 0;
  168.     if (qop->qualEntered[2]) count++;
  169.     if (qop->qualEntered[3]) count++;
  170.  
  171.     switch (count) {
  172.       case 0:
  173.     mLog = FALSE;
  174.     break;
  175.       case 1:
  176.     if (qop->qualEntered[2])
  177.       mLog = TRUE;
  178.     else
  179.       mLog = FALSE;
  180.     break;
  181.       case 2:
  182.     printf ("Conflicting qualifiers.\n");
  183.     ExitBAD;
  184.     break;
  185.     }
  186.  
  187.     break;
  188. }
  189.  
  190. /******************************************************************************
  191. * Open CDF.
  192. ******************************************************************************/
  193.  
  194. status = CDFlib (OPEN_, CDF_, CDFname, &id,
  195.          GET_, CDF_NUMATTRS_, &Nattrs,
  196.          NULL_);
  197. StatusHandler (status);
  198.  
  199. /******************************************************************************
  200. * Correct the scope of each attribute (if necessary).
  201. ******************************************************************************/
  202.  
  203. if (Nattrs == 0) {
  204.   if (mLog) printf ("No attributes in CDF.\n");
  205. }
  206. else {
  207.   for (attrN = 0; attrN < Nattrs; attrN++) {
  208.      status = CDFlib (SELECT_, CDF_, id,
  209.                    ATTR_, attrN,
  210.               GET_, ATTR_SCOPE_, &scope,
  211.                 ATTR_NAME_, attrName,
  212.               NULL_);
  213.      StatusHandler (status);
  214.  
  215.      switch (scope) {
  216.        case VARIABLE_SCOPE_ASSUMED:
  217.         if (confirm) {
  218.           printf ("Attribute %s has ASSUMED VARIABLE scope, correct? ",
  219.               attrName);
  220.           printf ("[y/n/g/v] => ");
  221.           scanf ("%s", answer);
  222.         }
  223.         else
  224.           answer[0] = 'y';
  225.  
  226.         switch (answer[0]) {
  227.           case 'y':
  228.           case 'Y':
  229.         status = CDFlib (SELECT_, CDF_, id,
  230.                  PUT_, ATTR_SCOPE_, VARIABLE_SCOPE,
  231.                  NULL_);
  232.         StatusHandler (status);
  233.         VARcount++;
  234.         break;
  235.           case 'n':
  236.           case 'N':
  237.         break;
  238.           case 'g':
  239.           case 'G':
  240.         status = CDFlib (SELECT_, CDF_, id,
  241.                  PUT_, ATTR_SCOPE_, GLOBAL_SCOPE,
  242.                  NULL_);
  243.         StatusHandler (status);
  244.         GBLcount++;
  245.         break;
  246.           case 'v':
  247.           case 'V':
  248.         status = CDFlib (SELECT_, CDF_, id,
  249.                  PUT_, ATTR_SCOPE_, VARIABLE_SCOPE,
  250.                  NULL_);
  251.             StatusHandler (status);
  252.         VARcount++;
  253.         break;
  254.         }
  255.         break;
  256.  
  257.        case GLOBAL_SCOPE_ASSUMED:
  258.         if (confirm) {
  259.           printf ("Attribute %s has ASSUMED GLOBAL scope, correct? ",
  260.               attrName);
  261.           printf ("[y/n/g/v] => ");
  262.           scanf ("%s", answer);
  263.         }
  264.         else
  265.           answer[0] = 'y';
  266.  
  267.         switch (answer[0]) {
  268.           case 'y':
  269.           case 'Y':
  270.         status = CDFlib (SELECT_, CDF_, id,
  271.                  PUT_, ATTR_SCOPE_, GLOBAL_SCOPE,
  272.                  NULL_);
  273.         StatusHandler (status);
  274.         GBLcount++;
  275.         break;
  276.           case 'n':
  277.           case 'N':
  278.         break;
  279.           case 'g':
  280.           case 'G':
  281.         status = CDFlib (SELECT_, CDF_, id,
  282.                  PUT_, ATTR_SCOPE_, GLOBAL_SCOPE,
  283.                  NULL_);
  284.         StatusHandler (status);
  285.         GBLcount++;
  286.         break;
  287.           case 'v':
  288.           case 'V':
  289.         status = CDFlib (SELECT_, CDF_, id,
  290.                  PUT_, ATTR_SCOPE_, VARIABLE_SCOPE,
  291.                  NULL_);
  292.         StatusHandler (status);
  293.         VARcount++;
  294.         break;
  295.         }
  296.         break;
  297.      }
  298.   }
  299.  
  300.   if (mLog) {
  301.     if (GBLcount == 0 && VARcount == 0)
  302.       printf ("No assumed scopes corrected and/or found.\n");
  303.     else {
  304.       printf ("%ld scope%s corrected to GLOBAL, ",
  305.           GBLcount, (GBLcount == 1 ? "" : "s"));
  306.       printf ("%ld scope%s corrected to VARIABLE.\n",
  307.           VARcount, (VARcount == 1 ? "" : "s"));
  308.     }
  309.   }
  310. }
  311.  
  312. /******************************************************************************
  313. * Close CDF and exit;
  314. ******************************************************************************/
  315.  
  316. status = CDFlib (SELECT_, CDF_, id,
  317.          CLOSE_, CDF_,
  318.          NULL_);
  319. StatusHandler (status);
  320.  
  321. Exit;
  322. }
  323.  
  324.  
  325. /******************************************************************************
  326. * StatusHandler.
  327. ******************************************************************************/
  328.  
  329. void StatusHandler (status)
  330. CDFstatus status;
  331. {
  332. char text[CDF_STATUSTEXT_LEN + 1];
  333.  
  334. if (status == CDF_OK) return;        /* Do nothing. */
  335.  
  336. CDFlib (SELECT_, CDF_STATUS_, status,
  337.     GET_, STATUS_TEXT_, text,
  338.     NULL_);
  339.  
  340. if (status < CDF_WARN) {
  341.   printf ("ERROR> %s\n", text);
  342.   CDFlib (SELECT_, CDF_, id,
  343.       CLOSE_, CDF_, id,
  344.       NULL_);
  345.   ExitBAD;
  346. }
  347. else
  348.   if (mLog)
  349.     if (status < CDF_OK)
  350.       printf ("WARNING> %s\n", text);
  351.     else
  352.       printf ("INFO> %s\n", text);
  353.  
  354. return;
  355. }
  356.